import requests
import time
import uuid
import base64
from datetime import datetime

# 生成 jqsign 的示例函数（此处简单示例，实际逻辑根据需求调整）
def generate_jqsign(jqnonce, timestamp):
    # 示例逻辑：将 jqnonce 和 timestamp 拼接，并进行 Base64 编码，取前16字符
    data = f"{jqnonce}{timestamp}"
    encoded = base64.b64encode(data.encode()).decode()[:16]
    return encoded

# 当前时间戳
timestamp = int(time.time() * 1000)

# 动态生成 UUID 作为 jqnonce
jqnonce = str(uuid.uuid4())

# 生成 jqsign
jqsign = generate_jqsign(jqnonce, timestamp)

# 格式化 starttime 为 "YYYY/MM/DD HH:MM:SS" 格式
start_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")

# 请求的 URL，包含动态参数
url = f"https://www.wjx.top/joinnew/processjq.ashx?shortid=tope34P&starttime={start_time}&cst={timestamp}&submittype=1&ktimes=22&hlv=1&rn=2031553359.73528486&jcn=3003010&nw=1&jwt=4&jpm=27&t={timestamp}&wxfs=100&jqnonce={jqnonce}&jqsign={jqsign}"

# 请求头
headers = {
    "Accept": "text/plain, */*; q=0.01",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Pragma": "no-cache",
    "Sec-Ch-Ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
    "Sec-Ch-Ua-Mobile": "?0",
    "Sec-Ch-Ua-Platform": "\"Windows\"",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "X-Requested-With": "XMLHttpRequest",
    "Referer": "https://www.wjx.top/vm/tope34P.aspx",
}

# 提交数据（请根据实际情况填写）
data = {
    "submitdata": "1$112}2$1221232"  # 示例数据，根据实际表单需要修改
}

# 发送 POST 请求
try:
    response = requests.post(url, headers=headers, data=data)
    response.raise_for_status()  # 检查请求是否成功
    print("表单提交成功")
    print("响应内容:", response.text)
except requests.RequestException as e:
    print("提交失败:", e)
